<template>
  <div>
    <el-card class="box-card">
      <template #header>
        <span>员工信息管理</span>
      </template>
      <!-- 查询条件 -->
      <div ref="searchForm" class="search-form">
        <m-form
          inline
          is-button
          form-type="search"
          size="mini"
          :options="searchForm.options"
          :all-btn="searchForm.btnList"
          @search="(funtion)=> searchForm.initSearch(funtion)"
          @get-model="(form)=> searchForm.form = form"
          @init-search="search"
          @save="search"
        />
      </div>

      <div v-hasPermission="'qm:auth:user:do'" class="m-b-10">
        <m-all-btn :button-list="overallBtn" />
      </div>

      <m-table
        v-loading="dataGrid.loading"
        :height="dataGrid.height"
        :list="dataGrid.data"
        :columns="dataGrid.columns"
        :pagination="dataGrid.pagination"
        @handle-pagination-change="dataGrid.changePagination"
        @select-change="dataGrid.selectChange"
      >
        <template #action="scope">
          <m-all-btn :button-list="dataGrid.btnList" :scope="scope" />
        </template>
      </m-table>
    </el-card>

    <!-- 新增编辑 -->
    <template v-for="item in modalFormList">
      <m-modal-form
        :key="item.id"
        :width="item.form.width"
        :title="item.form.formType !== 'add' ? item.form.title[0] :item.form.title[1]"
        :form-attrs="item.form.formAttrs"
        :visible.sync="item.form.visible"
        :form-type="item.form.formType"
        :options="item.form.options"
        :btn-text="item.form.btnText"
        @save="(formData) => save(formData,item.form.save)"
      />
    </template>

  </div>
</template>

<script>

import { upUserBasic } from "@/api/user";

// 混入 minxin 文件夹下面所有的js文件
const files = require.context("./mixins", false, /\.js$/);
const minxins = [];
files.keys().forEach(key => {
  minxins.push(files(key).default || files(key));
});

import { managerUpPwd } from "@/api/user";

export default {
  name: "AtteException",
  mixins: [...minxins],
  data() {
    return {
      // 所有弹框表单集合
      modalFormList: []
    };
  },
  created() {
    this.setModalFormList();
  },

  methods: {
    setModalFormList() {
      this.modalFormList = [
        {
          id: 1,
          form: this.registerForm
        },
        {
          id: 2,
          form: this.passwordForm
        }
      ];
    },
    async save(formData, flag) {
      if (flag === "save") {
        await upUserBasic(formData);
        this.registerForm.visible = false;
      } else if (flag === "pwd") {
        await managerUpPwd(formData);
      }
      this.$message.success("操作成功");
      this.searchForm.refresh();
    }
  }
};
</script>
